<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates or open a shared memory segment</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.sem-remove.html">« sem_remove</a></li>
      <li style="float: right;"><a href="function.shm-detach.html">shm_detach »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.sem.html">Semaphore 函数</a></li>
    <li>Creates or open a shared memory segment</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.shm-attach" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">shm_attach</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">shm_attach</span> &mdash; <span class="dc-title">Creates or open a shared memory segment</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.shm-attach-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>shm_attach</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$key</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$size</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$permissions</code><span class="initializer"> = 0666</span></span>): <span class="type"><span class="type"><a href="class.sysvsharedmemory.html" class="type SysvSharedMemory">SysvSharedMemory</a></span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>shm_attach()</strong></span> returns an id that can be used to access
   the System V shared memory with the given <code class="parameter">key</code>, the
   first call creates the shared memory segment with 
   <code class="parameter">size</code> and the optional perm-bits 
   <code class="parameter">permissions</code>.
  </p>
  <p class="para">
   A second call to <span class="function"><strong>shm_attach()</strong></span> for the same
   <code class="parameter">key</code> will return a different <span class="classname"><a href="class.sysvsharedmemory.html" class="classname">SysvSharedMemory</a></span>
   instance, but both instances access the same underlying
   shared memory. <code class="parameter">size</code> and
   <code class="parameter">permissions</code> will be ignored.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.shm-attach-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">key</code></dt>

     <dd>

      <p class="para">
       A numeric shared memory segment ID
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">size</code></dt>

     <dd>

      <p class="para">
       The memory size. If not provided, default to the
       <code class="literal">sysvshm.init_mem</code> in the <var class="filename">php.ini</var>, otherwise 10000
       bytes.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">permissions</code></dt>

     <dd>

      <p class="para">
       The optional permission bits. Default to 0666.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.shm-attach-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a <span class="classname"><a href="class.sysvsharedmemory.html" class="classname">SysvSharedMemory</a></span> instance on success,  或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.shm-attach-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       On success, this function returns an <span class="classname"><a href="class.sysvsharedmemory.html" class="classname">SysvSharedMemory</a></span> instance now;
       previously, a <span class="type">resource</span> was returned.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">size</code> is nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.shm-attach-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.shm-detach.html" class="function" rel="rdfs-seeAlso">shm_detach()</a> - Disconnects from shared memory segment</span></li>
    <li class="member"><span class="function"><a href="function.ftok.html" class="function" rel="rdfs-seeAlso">ftok()</a> - Convert a pathname and a project identifier to a System V IPC key</span></li>
   </ul>
  </p>
 </div>
  

</div></div></div></body></html>